<?php
header("content-type: text/html; charset: utf-8");

//解析config.ini文件
$config = parse_ini_file(realpath(dirname(__FILE__) . '/config/config.ini'));

//从config 中获取数据库相关属性
$servername = $config["dbServername"];
$username = $config["dbUsername"];
$password = $config["dbPassword"];
$dbName = $config["dbName"];

//数据库连接
$mysqli = new mysqli($servername, $username, $password, $dbName);

//检测连接
if(mysqli_connect_error()) {
    die("连接失败: " . $conn->connect_error);
}

$sql = "SELECT id, username, password FROM user";
$result = $mysqli->query($sql); 
if($result->num_rows > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        echo "id: ". $row["id"]."-Name: " . $row["username"]. " " .$row["password"]. "<br>";
    }
}else {
    echo "0结果";
}

mysqli_close($mysqli);